package com.stormrage.edu.dao.exam.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.exam.ExmStudentAnswerDao;
import com.stormrage.entity.exam.ExmStudentAnswer;
import com.stormrage.entity.exam.rep.ExmStudentAnswerRep;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @Title: ExmStudentExamDaoImpl.java
 * @Package com.stormrage.edu.dao.exam.impl
 * @Description: 学员考试试题答案 Dao
 * @author www.stormragetech.com
 * @date 2016年5月17日
 * @version V1.0
 */
@Repository
public class ExmStudentAnswerDaoImpl extends MysBaseDao implements ExmStudentAnswerDao {

	private static final Logger logger = LoggerFactory.getLogger(ExmStudentAnswerDaoImpl.class);

	@Override
	public Integer create(final ExmStudentAnswer arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 ExmStudentAnswerDao 】-【 queryById 】-【 STARTED 】");

		final String query = "INSERT INTO exm_student_answer (stu_exam_id, answer, correct) VALUES"
				+ " (:stuExamId, :answer, :correct)";
		logger.debug(" 数据库执行语句为 " + query);

		Integer index = create(query, arg0);

		logger.debug(" 【 Dao 】-【 ExmStudentAnswerDao 】-【 queryById 】-【 COMPLETED 】");
		return index;

	}

	@Override
	public void delete(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 ExmStudentAnswerDao 】-【 delete 】-【 STARTED 】");

		final String query = "DELETE FROM exm_student_answer WHERE stu_exam_id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, map);

		logger.debug(" 【 Dao 】-【 ExmStudentAnswerDao 】-【 delete 】-【 COMPLETED 】");

	}

	@Override
	public List<ExmStudentAnswer> queryByExamId(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 ExmStudentAnswerDao 】-【 queryById 】-【 STARTED 】");

		final String query = "SELECT * FROM exm_student_answer WHERE stu_exam_id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		List<ExmStudentAnswer> array = queryList(query, ExmStudentAnswer.class, map);

		logger.debug(" 【 Dao 】-【 ExmStudentAnswerDao 】-【 queryById 】-【 COMPLETED 】");
		return array;

	}

	@Override
	public List<ExmStudentAnswerRep> queryRepByExamId(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 ExmStudentAnswerDao 】-【 queryRepByExamId 】-【 STARTED 】");

		final String query = "SELECT * FROM exm_student_answer WHERE stu_exam_id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		List<ExmStudentAnswerRep> array = queryList(query, ExmStudentAnswerRep.class, map);

		logger.debug(" 【 Dao 】-【 ExmStudentAnswerDao 】-【 queryRepByExamId 】-【 COMPLETED 】");
		return array;

	}

	@Override
	public List<ExmStudentAnswerRep> queryRepByExamCorr(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 ExmStudentAnswerDao 】-【 queryRepByExamId 】-【 STARTED 】");

		final String query = "SELECT * FROM exm_student_answer WHERE stu_exam_id = :id AND correct = :correct";
		logger.debug(" 数据库执行语句为 " + query);

		List<ExmStudentAnswerRep> array = queryList(query, ExmStudentAnswerRep.class, map);

		logger.debug(" 【 Dao 】-【 ExmStudentAnswerDao 】-【 queryRepByExamId 】-【 COMPLETED 】");
		return array;

	}

}
